function X = SampleData(img,num)

[H,W,Band] = size(img);
X = zeros(num,Band); % NxD

if num>H*W
    disp('Sample number is too big');
    return;
end

idsH = randperm(H);
idsW = randperm(W);

for i=1:num
    X(i,:) = img( idsH(i), idsW(i), : );
end


end